package com.cmc.cloud.cmclink.doc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.vo.CustomsCountry56CreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.CustomsCountry56PageReqVO;
import com.cmc.cloud.cmclink.doc.vo.CustomsCountry56UpdateReqVO;
import com.cmes.framework.common.exception.util.ServiceExceptionUtil;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;


import java.util.*;

import com.cmc.cloud.cmclink.doc.service.CustomsCountry56Service;
import com.cmc.cloud.cmclink.doc.entity.CustomsCountry56DO;
import com.cmc.cloud.cmclink.doc.mapper.CustomsCountry56Mapper;
import com.cmc.cloud.cmclink.doc.constants.errorconstant.CustomsCountry56ErrorCodeConstants;


/**
 * 国家56号令国家的标识符数据 Service 实现类
 *
 * @author 招商轮船-管理员
 */
@Service
@Validated
public class CustomsCountry56ServiceImpl implements CustomsCountry56Service {

    @Resource
    private CustomsCountry56Mapper customsCountry56Mapper;

    @Override
    public void createCustomsCountry56(CustomsCountry56CreateReqVO createReqVO) {
        // 插入
        CustomsCountry56DO customsCountry56 = BeanUtil.copyProperties(createReqVO, CustomsCountry56DO.class);
        customsCountry56Mapper.insert(customsCountry56);
    }

    @Override
    public void updateCustomsCountry56(CustomsCountry56UpdateReqVO updateReqVO) {
        // 校验存在
        validateCustomsCountry56Exists(updateReqVO.getId());
        // 更新
        CustomsCountry56DO updateObj = BeanUtil.copyProperties(updateReqVO, CustomsCountry56DO.class);
        customsCountry56Mapper.updateById(updateObj);
    }

    @Override
    public void deleteCustomsCountry56(Long id) {
        // 校验存在
        validateCustomsCountry56Exists(id);
        // 删除
        customsCountry56Mapper.deleteById(id);
    }

    private void validateCustomsCountry56Exists(Long id) {
        if (customsCountry56Mapper.selectById(id) == null) {
            throw ServiceExceptionUtil.exception(CustomsCountry56ErrorCodeConstants.CUSTOMS_COUNTRY56_NOT_EXISTS);
        }
    }

    @Override
    public CustomsCountry56DO getCustomsCountry56(Long id) {
        return customsCountry56Mapper.selectById(id);
    }

    @Override
    public List<CustomsCountry56DO> getCustomsCountry56List(Collection<Long> ids) {
        return customsCountry56Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<CustomsCountry56DO> getCustomsCountry56Page(CustomsCountry56PageReqVO reqVO) {
        LambdaQueryWrapperX<CustomsCountry56DO> queryWrapper = new LambdaQueryWrapperX<CustomsCountry56DO>()
                .likeIfPresent(CustomsCountry56DO::getCountryCname, reqVO.getCountryCname())
                .likeIfPresent(CustomsCountry56DO::getCountryEname, reqVO.getCountryEname())
                .likeIfPresent(CustomsCountry56DO::getCountryCode, reqVO.getCountryCode());
        return customsCountry56Mapper.selectPage(reqVO, queryWrapper);
    }
}
